import { AppDispatch } from '..';
import {
  getArticleListByIdAPI,
  ArticleQueryParamsType,
  getArticleDetailByIdAPI,
} from '@/api/article';
export const getArticleListByIdAction = ({
  channel_id,
  timestamp = Date.now(),
}: ArticleQueryParamsType) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleListByIdAPI({ channel_id, timestamp });
    console.log('res  ----->  ', res);
    dispatch({ type: 'article/saveList', payload: { ...res.data, channel_id } });
  };
};

/** 根据id更新list */
export const updateArticleListByIdAction = ({
  channel_id,
  timestamp = Date.now(),
}: ArticleQueryParamsType) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleListByIdAPI({ channel_id, timestamp });
    dispatch({ type: 'article/udpateListById', payload: { ...res.data, channel_id } });
  };
};

/** 根据id查询文章详情 */
export const getArticleDetailByIdAction = (id: string) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleDetailByIdAPI(id);
    // 3.
    dispatch({ type: 'article/saveDetail', payload: res.data });
  };
};
